package com;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.jms.Topic;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.junit.Test;

public class ProducerTest {
	
	@Test
	public void topicProducer() throws JMSException
	{
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Connection conn = factory.createConnection();
		conn.start();
		
		Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		
		Topic topic = session.createTopic("topic_xx001");
		MessageProducer producer = session.createProducer(topic);
		TextMessage message = session.createTextMessage("I am Topic Producer!");
		producer.send(message);
		
		conn.stop();
		conn.close();
		System.out.println("end.....!");
	}
	
	
	
	public static void main(String[] args) throws JMSException {
		ConnectionFactory factory = new ActiveMQConnectionFactory("tcp://127.0.0.1:61616");
		Connection conn = factory.createConnection();
		conn.start();
		
		Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
		Queue queue = session.createQueue("xx001");
		MessageProducer producer = session.createProducer(queue);
		
			TextMessage message = session.createTextMessage("I am Producer!");
			producer.send(message);
		
		
		conn.stop();
		conn.close();
		System.out.println("end.....!");
	}
}
